<?php

use Bitrix\Main\Loader;

//main is usually included directly
$documentRoot = Loader::getDocumentRoot();
foreach(
	[
		'Bitrix\\Main' => '/bitrix/modules/main/lib',
		'Bitrix\\UI' => '/bitrix/modules/ui/lib',
		'Psr\\Container' => '/bitrix/modules/main/vendor/psr/container/src',
		'Psr\\Log' => '/bitrix/modules/main/vendor/psr/log/Psr/Log',
		'Psr\\Http\\Message' => '/bitrix/modules/main/vendor/psr/http-message/src',
		'Psr\\Http\\Client' => '/bitrix/modules/main/vendor/psr/http-client/src',
		'Http\\Promise' => '/bitrix/modules/main/vendor/php-http/promise/src',
		'PHPMailer\\PHPMailer' => '/bitrix/modules/main/vendor/phpmailer/phpmailer/src',
		'GeoIp2' => '/bitrix/modules/main/vendor/geoip2/geoip2/src',
		'MaxMind\\Db' => '/bitrix/modules/main/vendor/maxmind-db/reader/src/MaxMind/Db',
	]
	as $namespace => $namespacePath
)
{
	Loader::registerNamespace($namespace, $documentRoot . $namespacePath);
}
unset($namespace, $namespacePath);

spl_autoload_register([Loader::class, 'autoLoad']);

Loader::registerAutoLoadClasses(
	'main',
	[
		'bitrix\\main\\application' => 'lib/application.php',
		'bitrix\\main\\httpapplication' => 'lib/httpapplication.php',
		'bitrix\\main\\argumentexception' => 'lib/exception.php',
		'bitrix\\main\\argumentnullexception' => 'lib/exception.php',
		'bitrix\\main\\argumentoutofrangeexception' => 'lib/exception.php',
		'bitrix\\main\\argumenttypeexception' => 'lib/exception.php',
		'bitrix\\main\\notimplementedexception' => 'lib/exception.php',
		'bitrix\\main\\notsupportedexception' => 'lib/exception.php',
		'bitrix\\main\\invalidoperationexception' => 'lib/exception.php',
		'bitrix\\main\\objectpropertyexception' => 'lib/exception.php',
		'bitrix\\main\\objectnotfoundexception' => 'lib/exception.php',
		'bitrix\\main\\objectexception' => 'lib/exception.php',
		'bitrix\\main\\systemexception' => 'lib/exception.php',
		'bitrix\\main\\accessdeniedexception' => 'lib/exception.php',
		'bitrix\\main\\decodingexception' => 'lib/exception.php',
		'bitrix\\main\\io\\invalidpathexception' => 'lib/io/ioexception.php',
		'bitrix\\main\\io\\filenotfoundexception' => 'lib/io/ioexception.php',
		'bitrix\\main\\io\\filedeleteexception' => 'lib/io/ioexception.php',
		'bitrix\\main\\io\\fileopenexception' => 'lib/io/ioexception.php',
		'bitrix\\main\\io\\filenotopenedexception' => 'lib/io/ioexception.php',
		'bitrix\\main\\context' => 'lib/context.php',
		'bitrix\\main\\httpcontext' => 'lib/httpcontext.php',
		'bitrix\\main\\dispatcher' => 'lib/dispatcher.php',
		'bitrix\\main\\environment' => 'lib/environment.php',
		'bitrix\\main\\event' => 'lib/event.php',
		'bitrix\\main\\eventmanager' => 'lib/eventmanager.php',
		'bitrix\\main\\eventresult' => 'lib/eventresult.php',
		'bitrix\\main\\request' => 'lib/request.php',
		'bitrix\\main\\httprequest' => 'lib/httprequest.php',
		'bitrix\\main\\response' => 'lib/response.php',
		'bitrix\\main\\httpresponse' => 'lib/httpresponse.php',
		'bitrix\\main\\modulemanager' => 'lib/modulemanager.php',
		'bitrix\\main\\server' => 'lib/server.php',
		'bitrix\\main\\config\\configuration' => 'lib/config/configuration.php',
		'bitrix\\main\\config\\option' => 'lib/config/option.php',
		'bitrix\\main\\context\\culture' => 'lib/context/culture.php',
		'bitrix\\main\\data\\cache' => 'lib/data/cache.php',
		'bitrix\\main\\data\\cacheengineapc' => 'lib/data/cacheengineapc.php',
		'bitrix\\main\\data\\cacheenginememcache' => 'lib/data/cacheenginememcache.php',
		'bitrix\\main\\data\\cacheenginefiles' => 'lib/data/cacheenginefiles.php',
		'bitrix\\main\\data\\cacheenginenone' => 'lib/data/cacheenginenone.php',
		'bitrix\\main\\data\\connection' => 'lib/data/connection.php',
		'bitrix\\main\\data\\connectionpool' => 'lib/data/connectionpool.php',
		'bitrix\\main\\data\\icacheengine' => 'lib/data/cache.php',
		'bitrix\\main\\data\\hsphpreadconnection' => 'lib/data/hsphpreadconnection.php',
		'bitrix\\main\\data\\managedcache' => 'lib/data/managedcache.php',
		'bitrix\\main\\data\\taggedcache' => 'lib/data/taggedcache.php',
		'bitrix\\main\\data\\memcacheconnection' => 'lib/data/memcacheconnection.php',
		'bitrix\\main\\data\\memcachedconnection' => 'lib/data/memcachedconnection.php',
		'bitrix\\main\\data\\nosqlconnection' => 'lib/data/nosqlconnection.php',
		'bitrix\\main\\db\\arrayresult' => 'lib/db/arrayresult.php',
		'bitrix\\main\\db\\result' => 'lib/db/result.php',
		'bitrix\\main\\db\\connection' => 'lib/db/connection.php',
		'bitrix\\main\\db\\sqlexception' => 'lib/db/sqlexception.php',
		'bitrix\\main\\db\\sqlqueryexception' => 'lib/db/sqlexception.php',
		'bitrix\\main\\db\\transactionexception' => 'lib/db/sqlexception.php',
		'bitrix\\main\\db\\sqlexpression' => 'lib/db/sqlexpression.php',
		'bitrix\\main\\db\\sqlhelper' => 'lib/db/sqlhelper.php',
		'bitrix\\main\\db\\mysqlconnection' => 'lib/db/mysqlconnection.php',
		'bitrix\\main\\db\\mysqlresult' => 'lib/db/mysqlresult.php',
		'bitrix\\main\\db\\mysqlsqlhelper' => 'lib/db/mysqlsqlhelper.php',
		'bitrix\\main\\db\\mysqliconnection' => 'lib/db/mysqliconnection.php',
		'bitrix\\main\\db\\mysqliresult' => 'lib/db/mysqliresult.php',
		'bitrix\\main\\db\\mysqlisqlhelper' => 'lib/db/mysqlisqlhelper.php',
		'bitrix\\main\\db\\mssqlconnection' => 'lib/db/mssqlconnection.php',
		'bitrix\\main\\db\\mssqlresult' => 'lib/db/mssqlresult.php',
		'bitrix\\main\\db\\mssqlsqlhelper' => 'lib/db/mssqlsqlhelper.php',
		'bitrix\\main\\db\\oracleconnection' => 'lib/db/oracleconnection.php',
		'bitrix\\main\\db\\oracleresult' => 'lib/db/oracleresult.php',
		'bitrix\\main\\db\\oraclesqlhelper' => 'lib/db/oraclesqlhelper.php',
		'bitrix\\main\\diag\\httpexceptionhandleroutput' => 'lib/diag/httpexceptionhandleroutput.php',
		'bitrix\\main\\diag\\fileexceptionhandlerlog' => 'lib/diag/fileexceptionhandlerlog.php',
		'bitrix\\main\\diag\\exceptionhandler' => 'lib/diag/exceptionhandler.php',
		'bitrix\\main\\diag\\iexceptionhandleroutput' => 'lib/diag/iexceptionhandleroutput.php',
		'bitrix\\main\\diag\\exceptionhandlerlog' => 'lib/diag/exceptionhandlerlog.php',
		'bitrix\\main\\io\\file' => 'lib/io/file.php',
		'bitrix\\main\\io\\fileentry' => 'lib/io/fileentry.php',
		'bitrix\\main\\io\\path' => 'lib/io/path.php',
		'bitrix\\main\\io\\filesystementry' => 'lib/io/filesystementry.php',
		'bitrix\\main\\io\\ifilestream' => 'lib/io/ifilestream.php',
		'bitrix\\main\\localization\\loc' => 'lib/localization/loc.php',
		'bitrix\\main\\mail\\mail' => 'lib/mail/mail.php',
		'bitrix\\main\\mail\\tracking' => 'lib/mail/tracking.php',
		'bitrix\\main\\mail\\eventmanager' => 'lib/mail/eventmanager.php',
		'bitrix\\main\\mail\\eventmessagecompiler' => 'lib/mail/eventmessagecompiler.php',
		'bitrix\\main\\mail\\eventmessagethemecompiler' => 'lib/mail/eventmessagethemecompiler.php',
		'bitrix\\main\\mail\\internal\\event' => 'lib/mail/internal/event.php',
		'bitrix\\main\\mail\\internal\\eventattachment' => 'lib/mail/internal/eventattachment.php',
		'bitrix\\main\\mail\\internal\\eventmessage' => 'lib/mail/internal/eventmessage.php',
		'bitrix\\main\\mail\\internal\\eventmessagesite' => 'lib/mail/internal/eventmessagesite.php',
		'bitrix\\main\\mail\\internal\\eventmessageattachment' => 'lib/mail/internal/eventmessageattachment.php',
		'bitrix\\main\\mail\\internal\\eventtype' => 'lib/mail/internal/eventtype.php',
		'bitrix\\main\\text\\converter' => 'lib/text/converter.php',
		'bitrix\\main\\text\\emptyconverter' => 'lib/text/emptyconverter.php',
		'bitrix\\main\\text\\encoding' => 'lib/text/encoding.php',
		'bitrix\\main\\text\\htmlconverter' => 'lib/text/htmlconverter.php',
		'bitrix\\main\\text\\binarystring' => 'lib/text/binarystring.php',
		'bitrix\\main\\text\\xmlconverter' => 'lib/text/xmlconverter.php',
		'bitrix\\main\\type\\collection' => 'lib/type/collection.php',
		'bitrix\\main\\type\\date' => 'lib/type/date.php',
		'bitrix\\main\\type\\datetime' => 'lib/type/datetime.php',
		'bitrix\\main\\type\\dictionary' => 'lib/type/dictionary.php',
		'bitrix\\main\\type\\filterabledictionary' => 'lib/type/filterabledictionary.php',
		'bitrix\\main\\type\\parameterdictionary' => 'lib/type/parameterdictionary.php',
		'bitrix\\main\\web\\cookie' => 'lib/web/cookie.php',
		'bitrix\\main\\web\\uri' => 'lib/web/uri.php',
		'bitrix\\main\\sendereventhandler' => 'lib/senderconnector.php',
		'bitrix\\main\\senderconnectoruser' => 'lib/senderconnector.php',
		'bitrix\\main\\urlrewriterrulemaker' => 'lib/urlrewriter.php',
		'bitrix\\main\\update\\stepper' => 'lib/update/stepper.php',
		'bitrix\\main\\composite\\abstractresponse' => 'lib/composite/responder.php',
		'bitrix\\main\\composite\\fileresponse' => 'lib/composite/responder.php',
		'bitrix\\main\\composite\\memcachedresponse' => 'lib/composite/responder.php',
		'bitrix\\main\\security\\otpexception' => 'lib/security/securityexception.php',
		'CTimeZone' => 'classes/general/time.php',
		'CBXPunycode' => 'classes/general/punycode.php',
		'IBXVirtualIO' => 'classes/general/virtual_io.php',
		'IBXGetErrors' => 'classes/general/virtual_io.php',
		'CBXVirtualIo' => 'classes/general/virtual_io.php',
		'CBXVirtualFileBase' => 'classes/general/virtual_file.php',
		'CBXVirtualFile' => 'classes/general/virtual_file.php',
		'CBXVirtualDirectory' => 'classes/general/virtual_file.php',
		'CAllOption' => 'classes/general/option.php',
		'COption' => 'classes/general/option.php',
		'CAllPageOption' => 'classes/general/pageoption.php',
		'CPageOption' => 'classes/general/pageoption.php',
		'CAllSQLWhere' => 'classes/general/sqlwhere.php',
		'CSQLWhereExpression' => 'classes/general/sqlwhere.php',
		'CSQLWhere' => 'classes/mysql/sqlwhere.php',
		'CAllLanguage' => 'classes/general/language.php',
		'CLanguage' => 'classes/general/language.php',
		'CLangAdmin' => 'classes/general/language.php',
		'_CLangDBResult' => 'classes/general/langdbresult.php',
		'CAllAgent' => 'classes/general/agent.php',
		'CAgent' => 'classes/mysql/agent.php',
		'CApplicationException' => 'classes/general/applicationexception.php',
		'CAdminException' => 'classes/general/adminexception.php',
		'CAllSite' => 'classes/general/site.php',
		'CAllLang' => 'classes/general/site.php',
		'CSite' => 'classes/general/site.php',
		'CLang' => 'classes/general/site.php',
		'CHTTP' => 'classes/general/http.php',
		'CUtil' => 'classes/general/util.php',
		'CAllMain' => 'classes/general/main.php',
		'CMain' => 'classes/general/main.php',
	]
);

Loader::registerHandler([\Bitrix\Main\ORM\Loader::class, 'autoLoad']);

// old class names compatibility
require_once __DIR__.'/compatibility.php';
